<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $user_id 
 * @property int $to_user_id 
 * @property int $type 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class LikeTag extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'like_tags';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id','to_user_id','type','created_at','updated_at'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'to_user_id' => 'integer', 'type' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    const TYPE_LIKE = 1;
    const TYPE_HATE = 0;

    /**
     * 添加记录
     * @param int $user_id 用户ID
     * @param int $to_user_id 操作用户ID
     * @param int $type 操作类型
     */
    public static function addRecord
    (
        $user_id=0,
        $to_user_id=0,
        $type=1
    ){
        if(!$user_id || !$to_user_id) return false;
        return self::updateOrCreate([
            'user_id' => $user_id,
            'to_user_id' => $to_user_id
        ], [
            'type' => $type,
            'updated_at' => date('Y-m-d H:i:s')
        ]);
    }

    /**
     * 获取用户讨厌和感兴趣的用户ID
     * @param $user_id
     * @return array
     */
    public static function getTagByUid($user_id)
    {
        return self::where('user_id',$user_id)->pluck('to_user_id')->toArray();
    }
}